#!/usr/bin/perl
use strict ;
my $bigram_file="C:\\DOCUME~1\\Administrator\\workspace\\smsindex\\data\\ngrams.txt";
open(file,"$bigram_file") || die();
my $bigram_file1="C:\\DOCUME~1\\Administrator\\workspace\\smsindex\\data\\ngrams1.txt";
open(file1,">$bigram_file1") || die();

my @bigrams = <file>;
my @array =();
foreach my $bg (@bigrams){
	chomp($bg);
	my @words = split("[ ]+",$bg);
	my $count = pop(@words);
	my $bigram = join(" ",@words);
	my @w = ();
	push @w , $bigram;
	push @w , $count;
	
	push @array, \@w;
	
}
my $pos = 1;
@array = sort {$a->[$pos] <=> $b->[$pos]} @array; 

print $#array;

for(my $i=0; $i< $#array+1; $i++){
	print file1 @array->[$i][0]." : ".@array->[$i][1]."\n";
}